﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using SubSonic;
using Classes;
using System.Data;
using System.Collections.Specialized;
using System.Reflection;

namespace AvaliacaoWeb
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["Matric"] != null)
            {
                Response.Redirect("SelecionaAvaliacao.aspx");
            }

            btnLogar.Attributes.Add("onclick", "document.getElementById('imgCarregando').style.display='block'; this.disabled = true;" + ClientScript.GetPostBackEventReference(btnLogar, null) + ";");            
            
            if (IsPostBack)
            {                
                #region Verificando Login

                // Campos Selecionados
                Query qry = new Query(AAvaliador.Schema.TableName)
                .AddWhere(AAvaliador.Columns.Matric, Comparison.Equals, txtMatricula.Value.Trim())
                .AddWhere(AAvaliador.Columns.Senha, Comparison.Equals, txtSenha.Value.Trim());

                DataTable usuario = qry.ExecuteDataSet().Tables[0];
                
                if (usuario.Rows.Count > 0)
                {
                    Session.Add("Matric", usuario.Rows[0][AAvaliador.Columns.Matric].ToString());
                    Session.Add("Apelido", usuario.Rows[0][AAvaliador.Columns.Apelido].ToString());
                    Session.Add("Nome", usuario.Rows[0][AAvaliador.Columns.Nome].ToString());
                    Session.Add("FlgAva", usuario.Rows[0][AAvaliador.Columns.Flgava].ToString());
                    
                    Response.Redirect("SelecionaAvaliacao.aspx");
                }
                else
                {
                    lblMsgErro.Visible = true;
                    txtMatricula.Value = "";
                    txtSenha.Value = "";
                    txtMatricula.Focus();
                }
                #endregion
            }     
                   
            if ((DateTime.Now.Hour >= 5 ) || (DateTime.Now.Hour < 12))
                lblMensgaem.Text = "Bom Dia";

            if ((DateTime.Now.Hour >= 12) || (DateTime.Now.Hour < 18))
                lblMensgaem.Text = "Boa Tarde";

            if ((DateTime.Now.Hour > 17) || (DateTime.Now.Hour < 5))
                lblMensgaem.Text = "Boa Noite";

            lblData.Text = " / Belém - PA, " + DateTime.Today.ToLongDateString();
        }

        protected void btnLogar_Click(object sender, EventArgs e)
        {
            
        }

    }
}